//
//  KDDayController.m
//  KongDays
//
//  Created by deeplu on 12. 12. 20..
//  Copyright (c) 2012년 BlueBeans. All rights reserved.
//

#import "KDDayController.h"
#import "KDNewDayController.h"
#import "KDAppDelegate.h"
#import "NSDay.h"

@interface KDDayController ()

- (void)initNavigationBar;
- (void)editDay;
- (void)deleteDay;

@end

@implementation KDDayController
@synthesize day = day_;
@synthesize titleLabel;

- (id)init
{
    self = [super initWithNibName:@"KDDayController" bundle:nil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [self.day release];
    [self.titleLabel release];
    [super dealloc];
}

#pragma mark - UIViewController methods

- (void)viewDidLoad
{
    [super viewDidLoad];

    if (self.day)
    {
        self.title = self.day.title;
        self.titleLabel.text = self.day.title;
        
        [self initNavigationBar];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Private methods

- (void)initNavigationBar
{
    UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Edit"
                                   style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(editDay)];
    
    self.navigationItem.rightBarButtonItem = editButton;
    
    [editButton release];
}

- (void)editDay
{
    KDNewDayController *editDayController =
        [[[KDNewDayController alloc] init] autorelease];
    
    editDayController.dayToEdit = self.day;
    
    [self.navigationController pushViewController:editDayController
                                         animated:YES];
}

- (void)deleteDay
{
    
}

@end
